<template>
  <div style="height: 80px;line-height: 95px;box-shadow: 2px 0 5px rgba(62,76,89,0.35)">
    <el-form :inline="true" style="margin-left: 30px">
      <el-form-item label="一级分类">
        <el-select v-model="categoryStore.c1Id" @change="handler1" :disabled="scene==1?true:false"
                   placeholder="请选择分类" style="width: 250px">
          <!--label：即为展示数据 value:即为select下拉菜单收集的数据-->
          <el-option v-for="c1 in categoryStore.c1Arr" :key="c1.id" :label="c1.name" :value="c1.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="categoryStore.c2Id" @change="handler2" :disabled="scene==1?true:false" placeholder="请选择分类" style="width: 250px">
          <el-option v-for="c2 in categoryStore.c2Arr" :key="c2.id" :label="c2.name" :value="c2.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="categoryStore.c3Id" :disabled="scene==1?true:false" placeholder="请选择分类" style="width: 250px">
          <el-option v-for="c3 in categoryStore.c3Arr" :key="c3.id" :label="c3.name" :value="c3.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
//引入生命周期函数钩子
import { onMounted } from 'vue'
//引入分类相关的仓库
import useCategoryStore from '@/store/modules/category.ts'

let categoryStore = useCategoryStore()
//组件挂载完毕
onMounted(() => {
  //获取一级分类数据
  getC1()
})
//通知仓库获取一级分类的数据
const getC1 = () => {
  //通知属性分类仓库获取一级分类的数据
  categoryStore.getC1()
}
//一级分类下拉菜单的change事件
const handler1 = () => {
  //清理二级，三级分类的数据
  categoryStore.c2Id = ''
  categoryStore.c3Id = ''
  categoryStore.c3Arr = []
  //通知仓库获取二级分类的数据
  categoryStore.getC2()
}
//二级分类下拉菜单的change事件
const handler2 = () => {
  //清理三级分类的数据
  categoryStore.c3Id = ''
  //通知仓库获取三级分类的数据
  categoryStore.getC3()
}

//接收父组件传递过来的scene
defineProps(['scene'])
</script>

<style scoped>

</style>
